package com.hxkj.service.article.impl;

import com.hxkj.client.service.LabelManagementServiceClient;
import com.hxkj.domain.po.LabelTags;
import com.hxkj.service.article.LabelManagementService;
import com.hxkj.token.utils.TokenUtils;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class LabelManagementServiceImpl implements LabelManagementService{


    @Autowired
    private LabelManagementServiceClient labelManagementServiceClient;

    @Override
    public void save(LabelTags labelTags)throws Exception{
        labelManagementServiceClient.save(labelTags);
    }

    @Override
    public ResultDataStruct<LabelTags> get(LabelTags labelTags) throws Exception {
        if (labelTags.getLabelId()==null) {
            throw new CustomMessageException(302,"模板标签管理id为空!");
        }
        ResultDataStruct<LabelTags>  labelTagsResultDataStruct =  labelManagementServiceClient.get(labelTags);
        Integer code =  labelTagsResultDataStruct.getCode();
        if(code != null){
            throw new CustomMessageException(labelTagsResultDataStruct.getCode(),labelTagsResultDataStruct.getMessage());
        }
        return labelTagsResultDataStruct;
    }

    @Override
    public List<LabelTags> getLabelTags(LabelTags labelTags) throws Exception {
        ResultDataStruct<List<LabelTags>> listResultDataStruct =  labelManagementServiceClient.getLabelTags(labelTags);
        if(listResultDataStruct.getCode()!=null){
            throw new CustomMessageException(listResultDataStruct.getCode(),listResultDataStruct.getMessage());
        }
        return listResultDataStruct.getData();
    }

    @Override
    public ResultMessageStruct modify(LabelTags labelTags) throws Exception {
        if(labelTags.getLabelId()==null){
            throw new CustomMessageException(302,"模板标签管理id为空!");
        }
        if(StringUtils.isEmpty(labelTags.getName())){
            throw new CustomMessageException(303,"模板标签管理名称不能为空!");
        }
        if(StringUtils.isEmpty(labelTags.getLabelName())){
            throw new CustomMessageException(304,"模板标签管理标签名为空!");
        }
        ResultMessageStruct resultMessageStruct = labelManagementServiceClient.modify(labelTags);
        if(resultMessageStruct.getCode() != null){
            throw new CustomMessageException(resultMessageStruct.getCode(),resultMessageStruct.getMessage());
        }
        return resultMessageStruct;
    }

    @Override
    public void remove(LabelTags labelTags) throws Exception {
        ResultMessageStruct resultMessageStruct =  labelManagementServiceClient.remove(labelTags);
        if(resultMessageStruct.getCode()!= null){
            throw new CustomMessageException(resultMessageStruct.getCode(),resultMessageStruct.getMessage());
        }
    }
}
